package py.filter.impl;

import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFCell;

import py.ColumnStrategy;
import py.filter.FilterCond;
import py.filter.FilterHandleInterface;
import py.filter.FilterManager;
import py.util.ToolUtil;

public class DelFilterHandle implements FilterHandleInterface {

//	private HashMap<Integer,ColumnStrategy> delConMap=new HashMap<Integer,ColumnStrategy>();
//    public HashMap<Integer, ColumnStrategy> getDelConMap() {
//		return delConMap;
//	}
//	public void setDelConMap(HashMap<Integer, ColumnStrategy> delConMap) {
//		this.delConMap = delConMap;
//	}
	//	public DelFilterHandle()
//	{
//		ArrayList<ColumnStrategy> list=SwitchConfig.getDesCols();
//		for (int i =0 ;i<list.size();i++) {
//			ColumnStrategy columnStrategy = list.get(i);
//			if(columnStrategy.getFc()!=null)
//			{
//				FilterCond fc=columnStrategy.getFc();
//				if(fc.getFilerType()=="del")
//					delConMap.put(i, columnStrategy);      //i为目标文件中的第几列
//			}
//		}
//	}
	@Override
	public XSSFCell[] handle(XSSFCell[] cs) {
		// TODO Auto-generated method stub
		Set<Entry<Integer, ColumnStrategy>> keyset=FilterManager.delConMap.entrySet();
		Iterator<Entry<Integer, ColumnStrategy>> it=keyset.iterator();
		while(it.hasNext())
		{
			Entry<Integer, ColumnStrategy> en =it.next();
			int conlumNum=en.getKey();
			//获取第几列
			XSSFCell cell = cs[conlumNum];
			ColumnStrategy columnStrategy = en.getValue();
			FilterCond fc=columnStrategy.getFc();
			String filterCon=fc.getFilterCon();
			int filterValue=Integer.parseInt(fc.getFilterValue());
			if("less".equals(filterCon.trim()))
			{
				try{
					
					double cellV=Double.parseDouble(ToolUtil.getCellValue(cell));
					if(Math.abs(cellV)<filterValue)
					{
						return null;
					}
						
				}catch (Exception ex)
				{
//					System.out.println("***********"+ex.getMessage()+"**********");
//					System.out.println("in DelRows Process,the Compared value is:"+cell.getStringCellValue());
				}
				
			}
			
			
		}
		return cs;
			
		
	}

}
